<?php
// +------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +------------------------------------------------------------------
// | Copyright © 2011-2016 载攸道 All rights reserved 
// +------------------------------------------------------------------
// | Project: YiPHP [ 我们会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +------------------------------------------------------------------
// | Team: 宏达游易工作室 <http://www.isdce.com>
// +------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +------------------------------------------------------------------

namespace Install\Controller;
use Think\Controller;
use Think\Storage;

class IndexController extends Controller{
	

	/**
	 * 安装首页
	 */
    public function Index(){
		
        if(is_file(APP_PATH . 'Common/Conf/db.php')){
            // 已经安装过了 执行更新程序
            //session('update',true);
            $msg = '请删除install.lock文件后再运行升级!';
        }else{
            $msg = '已经成功安装了YiPHP，请不要重复安装!';
        }
        if(Storage::has('../Backup/install.lock')){
            $this->error($msg);
        }
		
		 $version = C('YIPHP_VERSION');
		
		 $this->assign('version',$version);
		
        $this->display();
		
    }

	/**
	 * 安装完成
	 */
    public function Complete(){
        $step = session('step');

        if(!$step){
            $this->redirect('index');
        } elseif($step != 3) {
            $this->redirect("Install/step{$step}");
        }

        // 写入安装锁定文件
        Storage::put('../Backup/install.lock', 'lock');
        if(!session('update')){
            //创建配置文件
            $this->assign('info',session('config_file'));
        }
        session('step', null);
        session('error', null);
        session('update',null);
        $this->display();
    }
}
